﻿@model IEnumerable<WebDocDB.Models.DocumentCollection>

@if (@Model.Any())
{
    foreach (var item in Model)
    {
        <div class="CollectionGroup">
            <i class="glyphicon glyphicon-plus" id="iplus_c_@item.ID"></i>
            <i class="glyphicon glyphicon-minus" id="iminus_c_@item.ID" style="display: none"></i>
            @Ajax.ActionLink(item.ID, "DocumentsList", "Documents", new { collectionLink = item.Link }, new AjaxOptions() { UpdateTargetId = "pnlCollection_" + @item.ID, OnComplete = "expandCollection('" + @item.ID + "', '" + @item.Link + "')", OnFailure = "collectionError()" }, new { @class = "Collection", id = "Collection_" + @item.ID })           
            <div id="pnlCollection_@item.ID"></div>
        </div>
    }
}
else
{
    <div class="CollectionGroup">
        <i>No Collections found</i>
    </div>
}


<script>
    var selectedCollectionLink = "";
    var selectedCollectionID = "";

    function expandCollection(collectionId, collectionLink) {

        //Collapse all collections
        $("[id^=iplus_c_]").show();
        $("[id^=iminus_c_]").hide();        
        $("[id^=pnlCollection_]").hide();
        $("[id^=Collection_]").css({ 'font-weight': 'normal' });

        //Show the selected one
        $('#iplus_c_' + collectionId).toggle();
        $('#iminus_c_' + collectionId).toggle();
        $('#pnlCollection_' + collectionId).toggle();
        $('#Collection_' + collectionId).css({ 'font-weight': 'bold' });
        $('#btnDeleteCollection').show();
        $('#btnAddDocument').show();
        $('#btnAddDocumentFile').show();

        $('#iplus_c_' + collectionId).toggle();
        $('#iminus_c_' + collectionId).toggle();
        
        selectedCollectionLink = collectionLink;
        selectedCollectionID = collectionId;

        showQueryManager(selectedCollectionLink);
    }

    function collectionError() {
        showError('Error on retrieving Collection data');
    }    
</script>
